package model;

import java.awt.Color;
import java.awt.Graphics;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

public class Player {

	private int id;
	private String name;
	private Color color;
	private int[] direction;
	private ArrayList<Segment> tron;
	Socket socket;
	PrintWriter to;
	Scanner from;

	public Player(int id, String name, Color color, Socket socket,
			PrintWriter to, Scanner from) {
		this.id = id;
		this.name = name;
		this.color = color;
		this.tron = new ArrayList<Segment>();

		this.socket = socket;
		this.to = to;
		this.from = from;
	}

	public void addSegment(Segment[] segments) {
		for (Segment s : segments) {
			tron.add(s);
			s.setColor(this.color);
		}
	}

	public void move() {
		Segment oldHead = this.tron.get(0);
		Segment newHead = oldHead.add(this.direction);
		this.tron.add(0, newHead);
	}

	public boolean collides(ArrayList<Player> player) {
		return false;
	}

	public void paint(Graphics g) {
		for (Segment s : tron) {
			s.paint(g);
		}
	}

	public void send(String message) {
		this.to.println(message);
	}

	public String receive() {
		return this.from.nextLine();
	}

	public void setDirection(int[] dir) {
		this.direction = dir;
	}

}
